﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSimulation
{
    internal class CreditBank:Bank
    {
        //ArrayList是一种非泛型的集合，可以存储任何类型的数据，所以可以放不同的账户（Account和CreditAccount）
        ArrayList creditAccounts = new ArrayList();
        //隐藏父类函数CreatAccount
        new public Account CreatAccount(string id, string pwd, double money)
        {
            CreditAccount account = new CreditAccount(id, pwd, money);
            creditAccounts.Add(account);
            return account;
        }
        public CreditAccount CreatAccount(string id, string pwd, double money, double creditBalance)
        {
            CreditAccount creditAccount = new CreditAccount(id, pwd, money, creditBalance);
            creditAccounts.Add(creditAccount);
            return creditAccount;
        }

        //查找账户：输入id和密码返回账户对象，可以同时查找普通账户和信用账户
        new public CreditAccount GetAccount(string id, string pwd)
        {
            foreach(CreditAccount creditAccount in creditAccounts)
            {
                if(creditAccount.IsExist(id, pwd))
                {
                    return creditAccount;
                }
            }
            return null;
        }

        new public bool AccountIsExist(string id)
        {
            foreach (Account account in creditAccounts)
            {
                if (account.Id == id)
                {
                    return true;
                }
            }
            return false;
        }
    }
}
